// pages/clickMe/plan/index.js
import api from '../../../api/index'
import { userInfoStore } from '../../../store/userInfo'
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userLevel: 0,
    stepIndex: 0,
    progress:[
      { x: 110, y: -30, w: 50, h: 61, icon: '/images/clickme/icon_xr_1.png', x1: 240, y1: 25, image: '/images/clickme/icon_step_1.png', light: '/images/clickme/progress_1.png', text: '我的户型图', x2: 395, y2: 70},
      { x: 385, y: 125, w: 50, h: 61, icon: '/images/clickme/icon_xr_1.png', x1: 410, y1: 205, image: '/images/clickme/icon_step_2.png', light: '/images/clickme/progress_2.png', text: '我的方案', x2: 550, y2: 320},
      { x: 492, y: 370, w: 50, h: 60, icon: '/images/clickme/icon_xr_2.png', x1: 430, y1: 470, image: '/images/clickme/icon_step_3.png', light: '/images/clickme/progress_3.png', text: '我的服务协议', x2: 540, y2: 600},
      { x: 420, y: 620, w: 50, h: 60, icon: '/images/clickme/icon_xr_2.png', x1: 290, y1: 690, image: '/images/clickme/icon_step_4.png', light: '/images/clickme/progress_4.png', text: '我的施工进度', x2: 410, y2: 810},
      { x: 200, y: 770, w: 50, h: 70, icon: '/images/clickme/icon_xr_2.png', x1: 45, y1: 765, image: '/images/clickme/icon_step_5.png', light: '/images/clickme/progress_5.png', text: '我的评价', x2: 160, y2: 900}
     
    ],

    construction:null,
    contract:null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData(
      {
        userLevel: userInfoStore.userInfo.level
      });
  },

  onShow: function(){
    let self=this
    let param = {
      openId: userInfoStore.userInfo.openId
    }
    // let param = {
    //   openId: 'ofhiR4vgDWazdlvVd-gf0IIrtX_c'
    // }
    api.getMatchInfo(param).then(res => {
      let { diagrams, proposals, contracts, contract, construction, review} = res.result;
      let s = 1
      
      if (construction){
        if (construction.status==30)
        s = 5
        else
        s = 4

      } else if (contracts){
        s = 3 
      }
      else if (proposals)
        s = 2
      
      self.setData({ stepIndex: s, contract: contract, construction: construction})
    })
  },

  showComment:function(e){
    wx.navigateTo({
      url: 'comment',
    })
  },

  showdetail:function(e){
    let step = e.currentTarget.dataset.step;

    if(this.data.stepIndex<=step) return;

    if (step==0 || step==1){
      wx.navigateTo({
        url: 'layout?step='+step,
      })
    }
    if (step == 2) {
      wx.navigateTo({
        url: 'agreelist',
      })
    }
    if (step == 3) {
      wx.navigateTo({
        url: 'construction?id=' + this.data.construction.id,
      })
    }
    if (step == 4) {
      wx.navigateTo({
        url: 'comment?id=' + this.data.contract.id + '&saleUserId=' + this.data.contract.officerId + '&n=' + this.data.contract.userName + '&p=' + this.data.contract.userPhone,
      })
    }

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  }
})